﻿
//initial busy box
//NDK Loading
var ie45, ns6, ns4, dom;
if (navigator.appName == "Microsoft Internet Explorer") ie45 = parseInt(navigator.appVersion) >= 4;
else if (navigator.appName == "Netscape") {
    ns6 = parseInt(navigator.appVersion) >= 5;
    ns4 = parseInt(navigator.appVersion) < 5;
}
dom = ie45 || ns6;
var interval = '';
var loading = 0;
var timershow = false;
var curx = 0;
var cury = 320;
var win_w = window.innerWidth ? window.innerWidth : null; //document.body.offsetWidth;
var mid_w = win_w / 2;
var timershow1 = window.setInterval("stayMiddle()", 1);
//NDK Loading
function getobj(id) {
    el = document.all ? document.all[id] : dom ? document.getElementById(id) : document.layers[id];
    return el;
}

function show_Loading() {
    jQuery('#box-busy').fadeIn();
}

function hide_Loading() {
    jQuery('#box-busy').fadeOut();
}

function moveobj(obj, x, y) {
    if (obj != null) {
        ww = window.innerWidth ? window.innerWidth : document.body.offsetWidth;
        obj.style.left = (ww / 2) - (obj.offsetWidth / 2) + "px";
        obj.style.top = y + "px";
        curx = x;
        cury = y;
    }
}

function stayMiddle() {
    if (document.documentElement && document.documentElement.scrollTop)
        var pY = document.documentElement.scrollTop;
    else if (document.body)
        var pY = document.body.scrollTop;
    obj = getobj('box-busy');
    newy = cury + ((pY - cury) / 16) + 20;
    moveobj(obj, curx, newy);
}

function nshow() {
    obj = getobj('box-busy');
    newx = curx;
    moveobj(obj, newx, cury);
}
function nhide() {
    obj = getobj('box-busy');
    newx = curx;
    moveobj(obj, newx, cury);
}
//End busy-box

function makeDialog(dialogTitle, dialogId, dialogWidth, href) {
    var $dialog = $("<div></div>");
    $dialog.appendTo("body")
            .addClass("dialog")
            .attr("id", dialogId);

    $dialog.dialog({
        title: dialogTitle,
        modal: true,
        autoOpen: true,
        width: dialogWidth,
        resizable: true,
        bgiframe: true,
        draggable: true,
        resizeStop: function (event, ui) {
            var y = $(event.target).height();
            repEditor.resize("99%", y - 10);
        },
        position: ['middle', 50],
        close: function (event, ui) {
            $('.dialog').dialog("destroy");
            $('.dialog').remove();

        },
        zIndex: 1200
    }).load(href);
}

function makeEventDialog(selector) {
    $(selector).click(function (e) {
        e.preventDefault();
        makeDialog($(this).attr("data-dialog-title"),
        $(this).attr("data-dialog-id"),
        700,
        this.href);
    });

    return false;
}

function makeEventDialogFixHref(selector, width) {
    $(selector).click(function (e) {
        e.preventDefault();
        makeDialog($(this).attr("data-dialog-title"),
        $(this).attr("data-dialog-id"),
        width,
        $(this).attr("data-dialog-href"));
    });

    return false;
}

function loadViewAjax(elementSelector, urls) {
    $.ajax({
        url: urls,
        type: 'GET',
        dataType: 'html', // <-- to expect an html response
        success: function (result) {
            jQuery("" + elementSelector + "").html(result);
        }
    });

    setTimeout(function () {
        loadViewAjax(elementSelector, urls);
    }, 5000);

    return false;
}
